package cn.hunqing.web.util;

import java.io.File;

import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FileStoredPathUtils {

	private static final Logger LOG = LoggerFactory
			.getLogger(FileStoredPathUtils.class.getName());

	public static String generatePath(File rootDir, String uid, String fileName) {
		String digestedStudyInstanceUID = DigestUtils.md5Hex(uid);
		String first = digestedStudyInstanceUID.substring(0, 3);
		String second = digestedStudyInstanceUID.substring(3, 6);
		String third = digestedStudyInstanceUID.substring(6, 9);
		String forth = digestedStudyInstanceUID.substring(9, 12);
		String dataFolderStr =  File.separator + first + File.separator + second + File.separator
				+ third + File.separator + forth + File.separator;
		LOG.info("to store Path:" + dataFolderStr);
		File dataFile = new File(rootDir,dataFolderStr);
		dataFile.mkdirs();
		return dataFile.getAbsolutePath()+File.separator+fileName;
	}

}
